home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / semaphores.asm < prev    next >
Encoding:
Assembly Source File  |  1995-11-10  |  4.8 KB  |  127 lines

  1.                     SECTION   CODE
  2.  
  3.                     INCLUDE   "shared_defs.i"
  4.                     INCLUDE   "macros.i"
  5.                     INCLUDE   "exec/execbase.i"
  6.                     INCLUDE   "exec/ables.i"
  7.                     INCLUDE   "exec/semaphores.i"
  8.                     INCLUDE   "exec/funcdef.i"
  9.                     INCLUDE   "exec/exec_lib.i"
  10.  
  11.                     XDEF      VMMObtainSemaphore
  12.                     XDEF      VMMReleaseSemaphore
  13.                     XDEF      VMMInitSemaphore
  14.                     XDEF      _VMMObtainSemaphore
  15.                     XDEF      _VMMReleaseSemaphore
  16.                     XDEF      _VMMInitSemaphore
  17.  
  18. ******************************************************************************
  19. * This file implements the ObtainSemaphore and ReleaseSemaphore system calls.
  20. * They offer the same functionality as the system calls but they don't use the 
  21. * SIGB_SINGLE bit since this causes problems in conjunction with ramlib. 
  22. * Additionally it doesn't support nesting of semaphore calls.
  23. * The calls with the leading underscore take their argument on the stack
  24. * and the ones without take them in the usual register.
  25. ******************************************************************************
  26.  
  27.  STRUCTURE  MY_SSR,SSR_SIZE
  28.     ULONG   MY_SSR_SIGNAL
  29.     LABEL   MY_SSR_SIZE
  30.  
  31. VMMObtainSemaphore:
  32.                     * Called with:
  33.                     * a0: SignalSemaphore
  34.                     * a6: SysBase
  35.                     * This function does not modify any registers
  36.  
  37.                     FORBID
  38.                     addq.w    #1,SS_QUEUECOUNT(a0)
  39.                     bne       SemaInUse
  40.                     move.l    ThisTask(a6),SS_OWNER(a0)
  41.                     jmp       _LVOPermit(a6)
  42.  
  43. SemaInUse:          movem.l   d0-d1/a0-a1,-(sp)
  44.                     lea       -MY_SSR_SIZE(sp),sp
  45.                     move.l    ThisTask(a6),SSR_WAITER(sp)
  46.                     GET_SIGNAL
  47.                     moveq     #0,d1
  48.                     move.b    d0,d1
  49.                     move.l    d1,MY_SSR_SIGNAL(sp)
  50.                     lea       SS_WAITQUEUE(a0),a0
  51.                     move.l    sp,a1
  52.                     ADDTAIL
  53.                     moveq     #1,d0
  54.                     lsl.l     d1,d0
  55.                     jsr       _LVOWait(a6)
  56.                     move.l    MY_SSR_SIGNAL(sp),d0
  57.                     RELEASE_SIGNAL
  58.                     lea       MY_SSR_SIZE(sp),sp
  59.                     movem.l   (sp)+,d0-d1/a0-a1
  60.                     jmp       _LVOPermit(a6)
  61.  
  62. ******************************************************************************
  63.  
  64. _VMMObtainSemaphore:
  65.                     move.l    4(sp),a0
  66.                     move.l    a6,-(sp)
  67.                     move.l    4,a6
  68.                     bsr       VMMObtainSemaphore
  69.                     move.l    (sp)+,a6
  70.                     rts
  71.  
  72. ******************************************************************************
  73.  
  74. VMMReleaseSemaphore:
  75.                     * Called with:
  76.                     * a0: SignalSemaphore
  77.                     * a6: SysBase
  78.                     * This function does not modify any registers
  79.  
  80.                     FORBID
  81.                     clr.l     SS_OWNER(a0)
  82.                     subq.w    #1,SS_QUEUECOUNT(a0)
  83.                     bge       ReviveWaiter
  84.                     jmp       _LVOPermit(a6)
  85.  
  86. ReviveWaiter:       movem.l   d0-d1/a0-a3,-(sp)
  87.                     move.l    a0,a2                         ; save semaphore
  88.                     lea       SS_WAITQUEUE(a0),a0
  89.                     REMHEADQ  a0,a1,a3                      ; head node in a1 now
  90.                     move.l    MY_SSR_SIGNAL(a1),d1
  91.                     moveq     #1,d0
  92.                     lsl.l     d1,d0
  93.                     move.l    SSR_WAITER(a1),a1
  94.                     move.l    a1,SS_OWNER(a2)
  95.                     jsr       _LVOSignal(a6)
  96.                     movem.l   (sp)+,d0-d1/a0-a3
  97.                     jmp       _LVOPermit(a6)
  98.  
  99. ******************************************************************************
  100.  
  101. _VMMReleaseSemaphore:
  102.                     move.l    4(sp),a0
  103.                     move.l    a6,-(sp)
  104.                     move.l    4,a6
  105.                     bsr       VMMReleaseSemaphore
  106.                     move.l    (sp)+,a6
  107.                     rts
  108.  
  109. ******************************************************************************
  110.  
  111. VMMInitSemaphore    * Called with:
  112.                     * a0: SignalSemaphore
  113.  
  114.                     clr.l     SS_OWNER(a0)
  115.                     move.w    #-1,SS_QUEUECOUNT(a0)
  116.                     move.b    #NT_SIGNALSEM,LN_TYPE(a0)
  117.                     lea       SS_WAITQUEUE(a0),a1
  118.                     NEWLIST   a1
  119.                     rts
  120.  
  121. ******************************************************************************
  122.  
  123. _VMMInitSemaphore:  move.l    4(sp),a0
  124.                     bra       VMMInitSemaphore
  125.  
  126.                     END
  127.